<template>
  <div style="margin:20px">
    <el-form ref="form" :model="liveObj">
      <el-form-item label="直播名称：">
        <el-input v-model="liveObj.name" style="width:60%"></el-input>
      </el-form-item>
      <el-form-item label="直播简介：">
        <el-input type="textarea" v-model="liveObj.desc" style="width:60%;"></el-input>
      </el-form-item>
      <el-form-item label="直播分类：">
        <el-select v-model="liveObj.classId" placeholder="请选择">
          <el-option v-for="item in classList" :key="item.id" :label="item.name" :value="item.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="直播封面：">
        <el-upload
          :action="imageUploadUrl"
          :show-file-list="false"
          list-type="picture-card"
          :limit="1"
          name="avatar"
          :before-upload="handleBeforeUpload"
          :on-success="handleBannerSuccess"
          :on-remove="handleRemove"
        >
          <img v-if="liveObj.photo" :src="liveObj.photo" class="avatar" />
          <i v-else class="el-icon-plus"></i>
        </el-upload>
      </el-form-item>
      <el-form-item label="邀约海报：">
        <el-upload
          :action="imageUploadUrl"
          :show-file-list="false"
          list-type="picture-card"
          :limit="1"
          name="avatar"
          :before-upload="handleBeforeUploadi"
          :on-success="handleBannerSuccessi"
        >
          <img v-if="liveObj.photo" :src="liveObj.photo" class="avatar" />
          <i v-else class="el-icon-plus"></i>
        </el-upload>
      </el-form-item>
      <el-form-item label="邀请话术：">
        <el-input v-model="liveObj.subscribeWord" style="width:60%"></el-input>
      </el-form-item>
      <el-form-item label="轮播公告：">
        <el-input v-model="liveObj.swiperNotice" style="width:60%"></el-input>
      </el-form-item>
      <el-form-item label="直播时间：">
        <el-date-picker
          v-model="liveObj.startTime"
          type="datetime"
          placeholder="选择开始日期时间"
          @change="selectDate($event,1)"
        ></el-date-picker>
        <el-date-picker
          v-model="liveObj.endTime"
          type="datetime"
          placeholder="选择结束日期时间"
          @change="selectDate($event,2)"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="管理员：">
        <el-button @click="showUser = true,managerName = ''">添加管理员</el-button>
        <span v-if="managerName">管理员：{{managerName}}</span>
      </el-form-item>
      <el-form-item label="老师：">
        <el-button @click="showTeacher = true">添加老师</el-button>
        <span v-if="teacherName">管理员：{{teacherName}}</span>
      </el-form-item>

      <!-- <el-form-item label="老师简介：">
        <el-input type="textarea" v-model="liveObj.teacherDesc" style="width:60%;"></el-input>
      </el-form-item>-->
      <el-form-item label="直播详情：">
        <span>&nbsp;</span>
        <tinymce :height="300" v-model="liveObj.particulars" style="width: 705px;"></tinymce>
      </el-form-item>
      <el-form-item label="交流群详情：">
        <span>&nbsp;</span>
        <tinymce :height="300" v-model="liveObj.communicGroup" style="width: 705px;"></tinymce>
      </el-form-item>
      <el-form-item label="售卖方式：">
        <el-radio v-model="liveObj.type" :label="1">免费</el-radio>
        <el-radio v-model="liveObj.type" :label="2">付费</el-radio>
        <el-radio v-model="liveObj.type" :label="3">加密</el-radio>
      </el-form-item>
      <el-form-item label="价格：" v-if="liveObj.type == 2">
        <el-input v-model="liveObj.price" style="width:80px"></el-input>元
      </el-form-item>
      <el-form-item label="针对人员免费设置：" v-if="liveObj.type == 2">
        <el-checkbox label="针对VIP免费" v-model="freePeopel.vip"></el-checkbox>
        <el-checkbox label="针对合伙人免费" v-model="freePeopel.partner" name="type"></el-checkbox>
        <el-checkbox label="针对运营中心免费" v-model="freePeopel.center" name="type"></el-checkbox>
        <el-checkbox label="针对员工免费" v-model="freePeopel.staff" name="type"></el-checkbox>
      </el-form-item>
      <el-form-item label="密码：" v-if="liveObj.type == 3">
        <el-input v-model="liveObj.pwd" style="width:150px"></el-input>
      </el-form-item>
      <el-form-item label="是否选择活动：">
        <el-radio v-model="isActive" :label="1">是</el-radio>
        <el-radio v-model="isActive" :label="0">否</el-radio>

        <div v-if="isActive">
          <el-radio
            v-for="(item,index) in activeArray"
            :key="index"
            v-model="liveObj.activityId"
            :label="index+1"
          >{{item}}</el-radio>
          <div>
            <span>邀请</span>
            <el-input-number
              v-model="liveObj.condition"
              controls-position="right"
              style="width:100px"
            ></el-input-number>
            <span>
              人可获得
              <font v-if="liveObj.activityId">（{{activeArray[liveObj.activityId-1]}}）</font>
            </span>
            <span v-if="liveObj.activityId == 2">
              <el-input-number
                v-model="liveObj.Oblance"
                controls-position="right"
                style="width:100px"
              ></el-input-number>个
            </span>
          </div>
        </div>
      </el-form-item>

      <el-form-item label="报名填写信息：">
        <el-checkbox label="公司" v-model="message.company" name="type"></el-checkbox>
        <el-checkbox label="职位" v-model="message.job" name="type"></el-checkbox>
      </el-form-item>

      <el-form-item label="参与人数基数：">
        <el-input-number v-model="liveObj.number" placeholder="请输入参与人数基数" controls-position="right"></el-input-number>&nbsp;人
      </el-form-item>
      <el-form-item label="预约人数基数：">
        <el-input-number
          v-model="liveObj.subscribeNumber"
          placeholder="请输入预约人数基数"
          controls-position="right"
        ></el-input-number>&nbsp;人
      </el-form-item>

      <h2>关联商品：</h2>
      <el-form-item label="智库包：">
        <el-button @click="selectCourse()">选择智库包</el-button>
        <el-table v-if="!(courseArray == false)" :data="courseArray" border style="width: 700px">
          <el-table-column prop="name" label="名称" width="180"></el-table-column>
          <el-table-column prop="price" label="价格" width="180"></el-table-column>
          <el-table-column prop="currentPrice" label="现价">
            <template slot-scope="scope">
              <el-input-number
                v-model="scope.row.currentPrice"
                placeholder="请输入现价"
                style="width:60%"
                controls-position="right"
              ></el-input-number>&nbsp;元
            </template>
          </el-table-column>
          <el-table-column prop="address" label="操作">
            <template slot-scope="scope">
              <el-button @click="deleteCourse(scope.row)" size="mini" type="warning">移除</el-button>
              <el-button
                @click="startStopCourse(scope.row,1)"
                v-if="scope.row.status == 1"
                type="danger"
                size="mini"
              >停用</el-button>
              <el-button @click="startStopCourse(scope.row,0)" size="mini" v-else type="primary">启用</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-form-item>

      <el-form-item label="代理商定金：">
        <el-input-number
          v-model="liveObj.partnerPrice"
          placeholder="请输入定金金额"
          controls-position="right"
        ></el-input-number>&nbsp;元
      </el-form-item>
      <!-- <el-form-item label="商品：">
        <el-button @click="selectGoods">选择商品</el-button>
        <el-table v-if="!(goodsArray == false)" :data="goodsArray" border style="width: 50%">
          <el-table-column prop="name" label="名称" width="180"></el-table-column>
          <el-table-column prop="price" label="价格" width="180"></el-table-column>
          <el-table-column prop="currentPrice" label="现价">
            <template slot-scope="scope">
              <el-input-number
                v-model="scope.row.currentPrice"
                placeholder="请输入现价"
                style="width:60%"
                controls-position="right"
              ></el-input-number>&nbsp;元
            </template>
          </el-table-column>
          <el-table-column prop="address" label="操作">
            <template slot-scope="scope">
              <el-button @click="deleteGoods(scope.row)" size="mini" type="warning">移除</el-button>
              <el-button
                @click="startStopGoods(scope.row,1)"
                v-if="scope.row.status == 1"
                type="danger"
                size="mini"
              >停用</el-button>
              <el-button @click="startStopGoods(scope.row,0)" size="mini" v-else type="primary">启用</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-form-item>-->
      <!-- <el-form-item label="系统方案：">
        <el-button @click="selectColumn()">选择方案</el-button>
        <el-table v-if="!(columnArray == false)" :data="columnArray" border style="width: 700px">
          <el-table-column prop="name" label="名称" width="180"></el-table-column>
          <el-table-column prop="price" label="价格" width="180"></el-table-column>
          <el-table-column prop="currentPrice" label="现价">
            <template slot-scope="scope">
              <el-input-number
                v-model="scope.row.currentPrice"
                placeholder="请输入现价"
                style="width:60%"
                controls-position="right"
              ></el-input-number>&nbsp;元
            </template>
          </el-table-column>
          <el-table-column prop="address" label="操作">
            <template slot-scope="scope">
              <el-button @click="deleteColumn(scope.row)" size="mini" type="warning">移除</el-button>
              <el-button
                @click="startStopColumn(scope.row,1)"
                v-if="scope.row.status == 1"
                type="danger"
                size="mini"
              >停用</el-button>
              <el-button @click="startStopColumn(scope.row,0)" size="mini" v-else type="primary">启用</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" @click="creatLive()">立即创建</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>

    <el-dialog title="选择课程" :visible.sync="showCourse" width="40%">
      <el-input placeholder="请输入课程名或讲师姓名进行搜索" v-model="courseName" style="width:70%"></el-input>
      <el-button type="primary" icon="el-icon-search" size="small" @click="searchCourse()">搜索</el-button>
      <el-table
        ref="multipleTable"
        :data="courseList"
        tooltip-effect="dark"
        height="300"
        style="width: 100%;"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column prop="name" label="名称"></el-table-column>
        <el-table-column prop="price" label="价格"></el-table-column>
      </el-table>

      <span slot="footer" class="dialog-footer">
        <el-button @click="showCourse = false">取 消</el-button>
        <el-button type="primary" @click="confirmCourse()">确 定</el-button>
      </span>
    </el-dialog>

    <el-dialog title="选择课程" :visible.sync="showGoods" width="40%">
      <el-input placeholder="请输入课程名或讲师姓名进行搜索" v-model="goodsName" style="width:70%"></el-input>
      <el-button type="primary" icon="el-icon-search" size="small" @click="searchGoods()">搜索</el-button>
      <el-table
        ref="multipleTable"
        :data="goodsList"
        tooltip-effect="dark"
        height="300"
        style="width: 100%;"
        @selection-change="handleSelectionChangeGoods"
      >
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column prop="name" label="名称"></el-table-column>
        <el-table-column prop="price" label="价格"></el-table-column>
      </el-table>

      <span slot="footer" class="dialog-footer">
        <el-button @click="showGoods = false">取 消</el-button>
        <el-button type="primary" @click="confirmGoods()">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog title="选择系统方案" :visible.sync="showColumn" width="40%">
      <el-table
        ref="multipleTable"
        :data="columnList"
        tooltip-effect="dark"
        height="300"
        style="width: 100%;"
        @selection-change="handleSelectionChangeColumn"
      >
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column prop="name" label="名称"></el-table-column>
        <el-table-column prop="price" label="价格"></el-table-column>
      </el-table>

      <span slot="footer" class="dialog-footer">
        <el-button @click="showColumn = false">取 消</el-button>
        <el-button type="primary" @click="confirmColumn()">确 定</el-button>
      </span>
    </el-dialog>

    <el-dialog title="请选择管理员" :visible.sync="showUser" width="40%">
      <el-input
        placeholder="请输入姓名手机号进行搜索"
        v-model="managerName"
        @keyup.enter="addManage"
        style="width:70%"
      ></el-input>
      <el-button type="primary" icon="el-icon-search" size="small" @click="addManage()">搜索</el-button>
      <el-table
        ref="multipleTable"
        :data="userList"
        tooltip-effect="dark"
        height="300"
        style="width: 100%;"
        @selection-change="handleSelectionChangeGoods"
      >
        <el-table-column label="名称">
          <div style="display:flex" slot-scope="scope">
            <img style="width:50px;height:50px" :src="scope.row.avatar" alt />
            <div>
              <span>用户名：{{scope.row.userName}}</span>
              <p>手机号：{{scope.row.mobile}}</p>
            </div>
          </div>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button @click="selectUser(scope.row)">选择</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>

    <el-dialog title="请选择讲师" :visible.sync="showTeacher" width="40%">
      <el-input
        placeholder="请输入姓名进行搜索"
        v-model="teacherName"
        @keyup.enter="addTearcher"
        style="width:70%"
      ></el-input>
      <el-button type="primary" icon="el-icon-search" size="small" @click="addTearcher()">搜索</el-button>
      <el-table
        ref="multipleTable"
        :data="userList"
        tooltip-effect="dark"
        height="300"
        style="width: 100%;"
        @selection-change="handleSelectionChangeGoods"
      >
        <el-table-column label="名称">
          <div style="display:flex" slot-scope="scope">
            <img style="width:50px;height:50px" :src="scope.row.avatar" alt />
            <div>
              <span>用户名：{{scope.row.name}}</span>
            </div>
          </div>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button @click="selectTeacher(scope.row)">选择</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>
<script>
import { createLive, getMemberList } from "@/api/member";
import {
  saveSocialRoom,
  getManager,
  saveLecturer,
  classList
} from "@/api/social";
import { getCourseList } from "@/api/course";
import { toGetList } from "@/api/column";
import { getLecturerList } from "@/api/lecturer";
import { getGoodsList } from "@/api/goods";
import Tinymce from "@/components/Tinymce";
export default {
  data() {
    return {
      freePeopel: {
        vip: false,
        partner: false,
        center: false,
        staff: false
      },
      message: {
        company: false,
        job: false
      },
      isActive: "",
      liveObj: {
        name: "",
        message: "",
        desc: "",
        photo: "",
        startTime: "",
        type: "",
        pwd: "",
        price: "",
        particulars: "",
        manage: "",
        partnerPrice: null,
        activityId: "",
        condition: null,
        Oblance: null,
        teacherId: null,
        classId: null,
        communicGroup: "",
        number: "",
        subscribeNumber: "",
        subscribePhoto: "",
        subscribeWord: "",
        swiperNotice: ""
      },
      activeArray: ["线下礼物", "赠送欧币", "免费观看"],
      imageUploadUrl: process.env.BASE_API + "/common/live/imageUpload",
      radio: 1,
      courseList: [],
      showCourse: false,
      courseArray: [],
      courseSubmit: [],
      courseName: "",
      goodsList: [],
      goodsArray: [],
      goodsSubmit: [],
      showGoods: false,
      goodsName: "",
      userList: [],
      JGmanage: {},
      showUser: false,
      managerName: "",
      managerNone: "",
      columnList: [],
      columnArray: [],
      columnSubmit: [],
      showColumn: false,
      showTeacher: false,
      teacherName: "",
      JGTeacher: {},
      classList: []
    };
  },
  watch: {},
  created() {
    // var lett = this;
    // document.onkeydown = function(e) {
    //   var key = window.event.keyCode;
    //   if (key == 13) {
    //     lett.addManage();
    //   }
    // };
  },
  methods: {
    // aa() {
    //   this.addManage();
    // },
    confirmColumn() {
      let columnArray = [];
      for (let i = 0; i < this.columnArray.length; i++) {
        let obj = {
          columnId: this.columnArray[i].columnId,
          name: this.columnArray[i].name,
          price: this.columnArray[i].price,
          prodType: 3,
          currentPrice: "",
          status: 0
        };
        columnArray.push(obj);
      }
      this.columnArray = columnArray;
      // this.coueseSubmit = courseArray;
      console.log(this.courseArray);
      // console.log(this.coueseSubmit);
      this.showColumn = false;
    },
    deleteColumn(val) {
      for (let i = 0; i < this.columnArray.length; i++) {
        const element = this.columnArray[i];
        if (element.columnId == val.columnId) {
          this.columnArray.splice(i, 1);
        }
      }
      this.columnSubmit = this.columnArray;
    },
    startStopColumn(val, type) {
      if (type == 0) {
        //启用
        if (val.currentPrice == "") {
          this.$message.error("请填写现价");
          return;
        }
        for (let i = 0; i < this.columnArray.length; i++) {
          const element = this.columnArray[i];
          if (element.columnId == val.columnId) {
            this.columnSubmit.push(element);
          }
        }
        val.status = 1;
      } else {
        //停用
        for (let i = 0; i < this.columnSubmit.length; i++) {
          const element = this.columnSubmit[i];
          if (element.columnId == val.columnId) {
            this.columnSubmit.splice(i, 1);
          }
        }
        val.status = 0;
      }
      console.log(this.columnSubmit);
    },
    handleSelectionChangeColumn(val) {
      this.columnArray = val;
    },
    selectColumn() {
      toGetList().then(res => {
        this.columnList = res.data.data.columnData.data;
      });
      this.showColumn = true;
    },
    selectTeacher(val) {
      this.teacherName = val.name;
      this.JGTeacher = val;
      this.liveObj.teacherId = val.userId;
      
      this.showTeacher = false;
    },
    selectUser(val) {
      this.liveObj.manage = val.userId;
      this.JGmanage = val;
      this.managerName = val.userName;
      this.showUser = false;
    },
    addTearcher() {
      this.userList = [];
      // getMemberList({ limit: 10000, nickname: this.teacherName }).then(res => {
      //   console.log(res);
      //   this.userList = res.data.data.users.data;
      // });
      getLecturerList({ name: this.teacherName }).then(res => {
        this.userList = res.data.data.data;
      });
    },
    addManage() {
      this.userList = [];
      // getMemberList({ limit: 10000, nickname: this.managerName }).then(res => {
      //   console.log(res);
      //   this.userList = res.data.data.users.data;
      // });
      getManager({ userName: this.managerName }).then(res => {
        this.userList = res.data.data;
      });
      this.showUser = true;
    },
    //商品相关方法
    deleteGoods(val) {
      for (let i = 0; i < this.goodsArray.length; i++) {
        const element = this.goodsArray[i];
        if (element.mgId == val.mgId) {
          this.goodsArray.splice(i, 1);
        }
      }
      this.goodsSubmit = this.goodsArray;
    },
    startStopGoods(val, type) {
      if (type == 0) {
        //启用
        if (val.currentPrice == "") {
          this.$message.error("请填写现价");
          return;
        }
        for (let i = 0; i < this.goodsArray.length; i++) {
          const element = this.goodsArray[i];
          if (element.mgId == val.mgId) {
            this.goodsSubmit.push(element);
          }
        }
        val.status = 1;
      } else {
        //停用
        for (let i = 0; i < this.goodsSubmit.length; i++) {
          const element = this.goodsSubmit[i];
          if (element.mgId == val.mgId) {
            this.goodsSubmit.splice(i, 1);
          }
        }
        val.status = 0;
      }
      console.log(this.goodsSubmit);
    },
    handleSelectionChangeGoods(val) {
      this.goodsArray = val;
    },
    confirmGoods() {
      let goodsArray = [];
      for (let i = 0; i < this.goodsArray.length; i++) {
        let obj = {
          mgId: this.goodsArray[i].mgId,
          name: this.goodsArray[i].name,
          price: this.goodsArray[i].price,
          prodType: 2,
          currentPrice: "",
          status: 0
        };
        goodsArray.push(obj);
      }
      this.goodsArray = goodsArray;
      // this.coueseSubmit = courseArray;
      console.log(this.courseArray);
      // console.log(this.coueseSubmit);
      this.showGoods = false;
    },
    searchGoods() {
      getGoodsList({ limit: 10000, productName: this.goodsName }).then(res => {
        this.goodsList = res.data.data.list.data;
      });
    },
    selectGoods() {
      getGoodsList({ limit: 100000 }).then(res => {
        this.goodsList = res.data.data.list.data;
      });
      this.showGoods = true;
      console.log(this.goodsList);
    },
    // 课程选择相关方法
    searchCourse() {
      getCourseList({ limit: 100000, name: this.courseName }).then(res => {
        this.courseList = res.data.data.list.data;
      });
    },
    deleteCourse(val) {
      for (let i = 0; i < this.courseArray.length; i++) {
        const element = this.courseArray[i];
        if (element.courseId == val.courseId) {
          this.courseArray.splice(i, 1);
        }
      }
      this.courseSubmit = this.courseArray;
      console.log(this.courseArray);
      console.log(this.courseSubmit);
    },
    startStopCourse(val, type) {
      if (type == 0) {
        //启用
        if (val.currentPrice == "") {
          this.$message.error("请填写现价");
          return;
        }
        for (let i = 0; i < this.courseArray.length; i++) {
          const element = this.courseArray[i];
          if (element.courseId == val.courseId) {
            this.courseSubmit.push(element);
          }
        }
        val.status = 1;
      } else {
        //停用
        for (let i = 0; i < this.courseSubmit.length; i++) {
          const element = this.courseSubmit[i];
          if (element.courseId == val.courseId) {
            this.courseSubmit.splice(i, 1);
          }
        }
        val.status = 0;
      }
      console.log(this.courseSubmit);
    },
    confirmCourse() {
      let courseArray = [];
      for (let i = 0; i < this.courseArray.length; i++) {
        let obj = {
          courseId: this.courseArray[i].courseId,
          name: this.courseArray[i].name,
          price: this.courseArray[i].price,
          prodType: 1,
          currentPrice: "",
          status: 0
        };
        courseArray.push(obj);
      }
      this.courseArray = courseArray;
      // this.coueseSubmit = courseArray;
      console.log(this.courseArray);
      // console.log(this.coueseSubmit);
      this.showCourse = false;
    },
    selectCourse() {
      getCourseList({ limit: 100000 }).then(res => {
        // console.log(res.data.data.list.data);
        this.courseList = res.data.data.list.data;
      });
      this.showCourse = true;
    },
    handleSelectionChange(val) {
      // this.courseArray = this.courseArray.concat(val);
      this.courseArray = val;
    },
    // 添加课程
    creatLive() {
      var free = [];

      if (this.freePeopel.vip) {
        free.push(1);
      }
      if (this.freePeopel.partner) {
        free.push(2);
      }
      if (this.freePeopel.center) {
        free.push(3);
      }
      if (this.freePeopel.staff) {
        free.push(4);
      }
      console.log(free.toString());
      this.liveObj.FreePeople = free.toString();

      var message = [];
      if (this.message.company) {
        message.push(1);
      }
      if (this.message.job) {
        message.push(2);
      }
      this.liveObj.message = message.toString();
      // return;
      var prod = this.goodsSubmit.concat(this.courseSubmit);
      this.liveObj.prod = prod.concat(this.columnSubmit);
      console.log(this.liveObj);
      if (this.liveObj.name == "") {
        this.$message.warning("请填写直播名称");
        return;
      } else if (this.liveObj.desc == "") {
        this.$message.warning("请填写直播简介");
        return;
      } else if (this.liveObj.photo == "") {
        this.$message.warning("请填加直播图片");
        return;
      } else if (this.liveObj.startTime == "") {
        this.$message.warning("请填写直播开始时间");
        return;
      } else if (this.liveObj.classId == "" || this.liveObj.classId == null) {
        this.$message.warning("请填写直播分类");
        return;
      }
      // else if (this.liveObj.teacherId == "") {
      //   this.$message.warning("请填写直播讲师");
      //   return;
      // }
      // else if (this.liveObj.teacherDesc == "") {
      //   this.$message.warning("请填写老师简介");
      //   return;
      // }
      else if (this.liveObj.particulars == "") {
        this.$message.warning("请填写课程详情");
        return;
      } else if (this.liveObj.type == "") {
        this.$message.warning("请填写售卖方式");
        return;
      } else if (this.liveObj.type == 2 && this.liveObj.price == "") {
        this.$message.warning("请填写直播间价格");
        return;
      } else if (this.liveObj.type == 3 && this.liveObj.pwd == "") {
        this.$message.warning("请填写直播间密码");
        return;
      }

      createLive(this.liveObj).then(res => {
        let liveId = res.data.data;
        saveSocialRoom({
          name: this.liveObj.name,
          liveId: liveId,
          intro: this.liveObj.desc,
          manager: this.JGmanage,
          avatar: this.liveObj.photo,
          price: null,
          teacherId: this.JGTeacher,
          // manager: this.managerNone,
          isFree: 0,
          hasTeacher: -1,
          lecturerUserId: 0
        }).then(res => {
          console.log(res);

          this.$message.success(res.data.data.message);
        });

        this.$router.push({
          name: "liveList"
        });
      });
    },
    //选择时间
    selectDate(val, type) {
      var mounth = String(val).substring(4, 7);
      var day = String(val).substring(8, 10);
      var year = String(val).substring(11, 15);
      var time = String(val).substring(16, 25);
      console.log(day);
      console.log(year);
      console.log(time);
      if (mounth == "Jan") {
        mounth = 1;
      } else if (mounth == "Feb") {
        mounth = 2;
      } else if (mounth == "Mar") {
        mounth = 3;
      } else if (mounth == "Apr") {
        mounth = 4;
      } else if (mounth == "May") {
        mounth = 5;
      } else if (mounth == "Jun") {
        mounth = 6;
      } else if (mounth == "Jul") {
        mounth = 7;
      } else if (mounth == "Aug") {
        mounth = 8;
      } else if (mounth == "Sep") {
        mounth = 9;
      } else if (mounth == "Oct") {
        mounth = 10;
      } else if (mounth == "Nov") {
        mounth = 11;
      } else if (mounth == "Dec") {
        mounth = 12;
      }
      if (type == 1) {
        this.liveObj.startTime = `${year}-${mounth}-${day} ${time}`;
      } else if (type == 2) {
        this.liveObj.endTime = `${year}-${mounth}-${day} ${time}`;
      }
      console.log(this.liveObj.startTime);
    },
    // 保存图片路径
    handleBannerSuccess(val) {
      console.log(val);
      this.liveObj.photo = val.data.imageUrl;
    },
    handleBannerSuccessi(val) {
      console.log(val);
      this.liveObj.subscribePhoto = val.data.imageUrl;
    },
    handleRemove(val) {
      console.log(val);
    },
    handleBeforeUpload(file) {
      console.log("上传文件之前触发啊、。。。");
      const isImg =
        file.type == "image/jpeg" ||
        file.type == "image/png" ||
        file.type == "image/gif";
      if (!isImg) {
        this.$message.warning("上传图片只能是 JPG 或 PNG 格式");
      }
      const isLt3M = file.size / 1024 / 1024 < 3;
      if (!isLt3M) {
        this.$message.error("上传图片大小不能超过 3MB!");
      }
      return isImg && isLt3M;
    },
    handleBeforeUploadi(file) {
      console.log("上传文件之前触发啊、。。。");
      const isImg =
        file.type == "image/jpeg" ||
        file.type == "image/png" ||
        file.type == "image/gif";
      if (!isImg) {
        this.$message.warning("上传图片只能是 JPG 或 PNG 格式");
      }
      const isLt3M = file.size / 1024 / 1024 < 3;
      if (!isLt3M) {
        this.$message.error("上传图片大小不能超过 3MB!");
      }
      return isImg && isLt3M;
    },
    getClass() {
      classList().then(res => {
        this.classList = res.data.data;
      });
    }
  },
  mounted() {
    this.getClass();
  },
  components: {
    Tinymce
  }
};
</script>
<style scoped>
</style>
